<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/31
 * Time: 16:40
 */

namespace app\common\lib\chuanglan;




class Sms
{

    public $tplCode = [];
    public $yunpian = [];
    public $szmw = [];

    public function init()
    {

    }

    /**
     * 验证码内容
     * @param $type
     * @param $code
     * @return string
     */
    public function getCodeContent($type, $code)
    {
        $tpl = '【数字星球】您的验证码是{{code}}';
        switch ($type) {
            case 'login':
                $tpl = '【数字星球】尊敬的用户，您正在使用该手机号码登录，验证码为：{{code}},请正确输入并完成注册。若非本人操作，无需理会。';
                break;
        }
        return str_replace('{{code}}', $code, $tpl);
    }

    /**
     * 发送验证码主接口
     * @param $mobile
     * @param $type
     * @param $code
     * @return array
     * @return mixed|string
     */
    public function sendCode($mobile,$code,$type)
    {
        $content = $this->getCodeContent($type, $code);
        try {
            $sms = new SmsChuangLan();
            $result = $sms->sendSMS($mobile, $content);
            $jsonRes = json_decode($result,true);
            return $jsonRes;
        } catch (\Exception $e) {
            return $e->getMessage();
        }
    }
}